package kr.poturns.blink.internal;
import android.app.Service;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.IBinder;

/**
 * Blink의 백그라운드 서비스의 베이스 Part.
 * 블루투스 통신으로 전달받은 데이터들을 다루는 가교역할을 한다({@link InterDeviceManager}).
 * 
 * 
 * @author Yeonho.Kim
 * @since 2014.07.12
 *
 */
abstract class BlinkBaseService extends Service /*implements InterDeviceEventListener*/ {

	protected InterDeviceManager mInterDeviceManager;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		// 
		DeviceAnalyzer.getInstance(this).apply();
		
		// Device간 통신 모듈을 연결한다. 
		mInterDeviceManager = InterDeviceManager.getInstance(this);
		if (mInterDeviceManager == null) {
			
		}
		//mInterDeviceManager.setInterDeviceListener(this);
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		return START_STICKY;
	}
	
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		super.onConfigurationChanged(newConfig);
		
	}
	
	@Override
	public IBinder onBind(Intent intent) {
		
		if (InterDeviceManager.ACTION_NAME.equals(intent.getAction())) {
			return LinkStatusHandler.getInstance(mInterDeviceManager).getBinder();
		}
		
		return null;
	}

	@Override
	public void onRebind(Intent intent) {
		// TODO Auto-generated method stub
		
		super.onRebind(intent);
	}
	
	@Override
	public boolean onUnbind(Intent intent) {
		// TODO Auto-generated method stub

		return super.onUnbind(intent);
	}

	@Override
	public void onTrimMemory(int level) {
		// TODO Auto-generated method stub

		super.onTrimMemory(level);
	}
	
	@Override
	public void onLowMemory() {
		// TODO Auto-generated method stub

		super.onLowMemory();
	}
	
	@Override
	public void onTaskRemoved(Intent rootIntent) {
		// TODO Auto-generated method stub
		super.onTaskRemoved(rootIntent);

	}
	
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		if (mInterDeviceManager != null)
			mInterDeviceManager.destroy();
		
		super.onDestroy();
	}
	
}
